﻿<template>
  <div>
    <custom-field-form v-if="batchDataList" size="small" style="top:15px;width:650px;" :data="queryData"
                       :fields="[{id: 'year', name: '年度', component:{id:'year-picker',change:handleChangeYear}, colSpan: 8},
                       {id:'batchId',name:'任务名称',colSpan:16,
                       component:{id:'data-select',change:handleChangeBatch,data:this.batchDataList}},]">
    </custom-field-form>
    <el-tabs v-model="activeTab" v-loading="isLoading" type="border-card" lazy>
      <el-tab-pane label="建设单位" name="office-analysis">
        <query-table v-if="this.activeTab == 'office-analysis'" key="office-analysis" ref="office-analysis"
                     dataUrl="/project/analysis/office"
                     :beforeDisplayList="loadOffice"
                     :defaultQueryParams="queryData"
                     :columns="officeAnalysisColumns"
                     :exportFileName="batchInfo.name+'按建设单位统计数据'"
                     show-index
                     page-size="-1"
        >
          <el-row style="padding-bottom: 10px; flex-wrap: wrap">
            <el-col :key="timestamp+'_col_'" style=" padding-right:25px;">

            </el-col>
            <el-col :key="timestamp+'_col_'" style=" padding: 0 25px;">

              <meta-select size="small" type="project-type-analysis" style="width:200px;float: right"
                           v-model="officeSelectKey"
                           @change="(val)=>updateBySelectOfficeTypeChart(val)"></meta-select>
              <el-button  style="margin-right: 15px;float: right" type="primary" size="small"
                         @click="()=>{$refs[activeTab].exportTableData();}">导出表格
              </el-button>
            </el-col>

          </el-row>
          <v-chart :key="'chart_'+timestamp" :style="{width:'100%',height:'400px'}"
                   :option="officeAnalysisOption"></v-chart>

        </query-table>
      </el-tab-pane>
      <el-tab-pane label="新老区" name="area-mark-analysis">
        <query-table v-if="this.activeTab == 'area-mark-analysis'" key="area-mark-analysis" ref="area-mark-analysis"
                     dataUrl="/project/analysis/area"
                     :beforeDisplayList="loadArea"
                     :defaultQueryParams="queryData"
                     :columns="areaMarkAnalysisColumns"
                     :exportFileName="batchInfo.name+'按新老区统计数据'"
                     show-index
                     page-size="-1"
        >
          <el-row style="padding-bottom: 10px; flex-wrap: wrap">
            <el-col :key="timestamp+'_col_'" style=" padding: 0 25px;">
              <data-select size="small" style="width:200px;float: right" v-model="areaSelectKey"
                           @change="(val)=>updateBySelectAreaChart(val)" :data="projectTypeList"></data-select>
              <el-button  style="margin-right: 15px;float: right" type="primary"
                          @click="()=>{$refs[activeTab].exportTableData();}">导出表格
              </el-button>
            </el-col>
          </el-row>
          <v-chart :key="'chart_'+timestamp" :style="{width:'100%',height:'400px'}"
                   :option="areaAnalysisOption"></v-chart>
        </query-table>
      </el-tab-pane>

      <el-tab-pane label="大区" name="region-analysis">
        <query-table v-if="this.activeTab == 'region-analysis'" key="region-analysis" ref="region-analysis"
                     dataUrl="/project/analysis/region"
                     :beforeDisplayList="loadRegion"
                     :columns="regionAnalysisColumns"
                     :exportFileName="batchInfo.name+'按大区统计数据'"
                     :defaultQueryParams="queryData"
                     show-index
                     page-size="-1"
        >
          <el-row style="padding-bottom: 10px; flex-wrap: wrap">
            <el-col :key="timestamp+'_col_'" style=" padding: 0 25px;">
              <data-select size="small" style="width:200px;float: right" v-model="regionSelectKey"
                           @change="(val)=>updateBySelectRegionChart(val)" :data="projectTypeList"></data-select>
              <el-button  style="margin-right: 15px;float: right" type="primary" size="small"
                          @click="()=>{$refs[activeTab].exportTableData();}">导出表格
              </el-button>
            </el-col>
          </el-row>
          <v-chart :key="'chart_'+timestamp" :style="{width:'100%',height:'400px'}"
                   :option="regionAnalysisOption"></v-chart>
        </query-table>
      </el-tab-pane>
      <el-tab-pane label="产能类型" name="capacity-type-analysis">
        <query-table v-if="this.activeTab == 'capacity-type-analysis'" key="capacity-type-analysis" ref="capacity-type-analysis"
                     dataUrl="/project/analysis/capacity"
                     :beforeDisplayList="loadCapacity"
                     :defaultQueryParams="queryData"
                     :exportFileName="batchInfo.name+'按产能类型统计数据'"
                     :columns="capacityAnalysisColumns"
                     show-index
                     page-size="-1"
        >
          <el-row style="padding-bottom: 10px; flex-wrap: wrap">
            <el-col :key="timestamp+'_col_'" style=" padding: 0 25px;">
              <data-select size="small" style="width:200px;float: right" v-model="capacitySelectKey"
                           @change="(val)=>updateBySelectCapacityChart(val)" :data="projectTypeList"></data-select>
              <el-button  style="margin-right: 15px;float: right" type="primary" size="small"
                          @click="()=>{$refs[activeTab].exportTableData();}">导出表格
              </el-button>
            </el-col>
          </el-row>
          <v-chart :key="'chart_'+timestamp" :style="{width:'100%',height:'400px'}"
                   :option="capacityAnalysisOption"></v-chart>
        </query-table>
      </el-tab-pane>
      <el-tab-pane label="油藏类型" name="pool-type-analysis">
        <query-table v-if="this.activeTab == 'pool-type-analysis'" key="pool-type-analysis" ref="pool-type-analysis"
                     dataUrl="/project/analysis/pool"
                     :beforeDisplayList="loadPool"
                     :exportFileName="batchInfo.name+'按油藏类型统计数据'"
                     :columns="poolTypeAnalysisColumns"
                     :defaultQueryParams="queryData"
                     show-index
                     page-size="-1"
        >
          <el-row style="padding-bottom: 10px; flex-wrap: wrap">
            <el-col :key="timestamp+'_col_'" style=" padding: 0 25px;">
              <data-select size="small" style="width:200px;float: right" v-model="poolTypeSelectKey"
                           @change="(val)=>updateBySelectPoolTypeChart(val)" :data="projectTypeList"></data-select>
              <el-button  style="margin-right: 15px;float: right" type="primary" size="small"
                          @click="()=>{$refs[activeTab].exportTableData();}">导出表格
              </el-button>
            </el-col>
          </el-row>
          <v-chart :key="'chart_'+timestamp" :style="{width:'100%',height:'400px'}"
                   :option="poolAnalysisOption"></v-chart>
        </query-table>

      </el-tab-pane>

    </el-tabs>
  </div>

</template>

<script>
//单位 吨油利润对比
import DataSelect from "../../components/data-select";

const titleStyle = {
  color: '#130e0e',//字体颜色
  fontStyle: 'normal',//字体风格
  fontWeight: 'bold',//字体粗细
  fontFamily: 'sans-serif',//文字字体
  fontSize: 18,//字体大小
  lineHeight: 18,//字体行高
  align: 'center',//'left' | 'right' ，文字水平对齐方式
  verticalAlign: 'middle',//'top' | 'bottom' ，文字垂直对齐方式
};
//油藏
const chartOption = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    }
  },
  color: [
    '#30c0b4',
    '#ef822f',
  ],
  legend: {top: 10,},
  grid: {
    left: 0,
    right: 10,
    bottom: 0,
    containLabel: true
  },
  xAxis: {
    axisLabel: {interval: 0},
    type: 'category',
    data: []
  },
  yAxis: {
    type: 'value',
    // show:false,
    axisLabel: {
      show: true,
      interval: 'auto',
      formatter: '{value} '
    },
    show: true

  },
  series: [
    {
      name: '达标',
      type: 'bar',
      // stack: 'Ad',
      // emphasis: {
      //   focus: 'series'
      // },
      label: {
        show: true,
        color: 'white'
      },
      data: []
    },
    {
      name: '未达标',
      type: 'bar',
     // stack: 'Ad',
      label: {
        show: true,
        color: 'white'
      },

      // emphasis: {
      //   focus: 'series'
      // },
      data: []
    },
    {
      type: 'scatter',
      name: '合计',
      //stack: 'Ad',
      label: {
        normal: {
          show: true,
          position: 'insideBottom',
          color: '#000'
        }
      },
      symbolSize: 12,
    //  barWidth: '25%',
      itemStyle: {
        normal: {
          color: 'red'    // 仍为透明
        }
      },

      yAxisIndex: 0,
      //不同系列的柱间距离，为百分比,如果想要两个系列的柱子重叠，可以设置 barGap 为 '-100%'。
      data: []
    },
  ]

};
export default {
  components: {DataSelect},
  $$route: {
    meta: {
      title: '统计分析'
    }
  },
  name: "AnalysisInfo",
  props: {
    pageHeight: {},
  },
  data() {
    return {
      regionAnalysisOption: JSON.parse(JSON.stringify(chartOption)),
      officeAnalysisOption: JSON.parse(JSON.stringify(chartOption)),
      poolAnalysisOption: JSON.parse(JSON.stringify(chartOption)),
      areaAnalysisOption: JSON.parse(JSON.stringify(chartOption)),
      capacityAnalysisOption: JSON.parse(JSON.stringify(chartOption)),
      isLoading: false,
      // queryData:{year:new Date().getFullYear()},
      queryData: {batchId: '', year: new Date().getFullYear()},
      projectTypeList: [],
      poolProfitTonData: [],
      areaSelectKey: 'totalInvest',
      capacitySelectKey: 'totalInvest',
      poolTypeSelectKey: 'totalInvest',
      officeSelectKey: 'totalInvest',
      regionSelectKey: 'totalInvest',
      //加载完成状态
      // index: 'record-module',
      activeTab: 'office-analysis',
      timestamp: new Date().getTime(),
      batchInfo: {},
      poolTypeMap: {},
      regionMap: {},
      capacityMap: {},
      poolTypeList: {},
      officeMap: {},
      officeAnalysisColumns: [
        {id: 'buildOffice', name: '建设单位', type: 'office', colSpan: 6},
        {
          id: 'totalInvest', name: '建设投资', unit: '亿元', readonly: true,
          children: [
            {id: 'totalInvestSum', name: '合计',},
            {id: 'totalInvestPass', name: '达标',},
            {id: 'totalInvestFailed', name: '未达标',},
          ]
        },
        {
          id: 'infWellCount', name: '基建井数', unit: '口', readonly: true,
          children: [
            {id: 'infWellCountSum', name: '合计',},
            {id: 'infWellCountPass', name: '达标',},
            {id: 'infWellCountFailed', name: '未达标',},
          ]
        },
        {
          id: 'newCapacity', name: '新建产能', unit: '万吨', readonly: true,
          children: [
            {id: 'newCapacitySum', name: '合计',},
            {id: 'newCapacityPass', name: '达标',},
            {id: 'newCapacityFailed', name: '未达标',},
          ]
        },
        {
          id: 'netProfit', name: '净利润', unit: '亿元', readonly: true,
          children: [
            {id: 'netProfitSum', name: '合计',},
            {id: 'netProfitPass', name: '达标',},
            {id: 'netProfitFailed', name: '未达标',},
          ]
        },
        {
          id: 'mTProductivityInvest', name: '百万吨产能投资', unit: '亿元', readonly: true,
          children: [
            {id: 'mTProductivityInvestSum', name: '合计',},
            {id: 'mTProductivityInvestPass', name: '达标',},
            {id: 'mTProductivityInvestFailed', name: '未达标',},
          ]
        },
        {
          id: 'wellInvest', name: '单井投资', unit: '万元', readonly: true,
          children: [
            {id: 'wellInvestSum', name: '合计',},
            {id: 'wellInvestPass', name: '达标',},
            {id: 'wellInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellEor', name: '单井EUR', unit: '吨', readonly: true,
          children: [
            {id: 'wellEorSum', name: '合计',},
            {id: 'wellEorPass', name: '达标',},
            {id: 'wellEorFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellEor', name: '单位操作成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitOperateCostDollarSum', name: '合计',},
            {id: 'unitOperateCostDollarPass', name: '达标',},
            {id: 'unitOperateCostDollarFailed', name: '未达标',},

          ]
        },
        {
          id: 'unitTotalOperateCostDollar', name: '单位完全成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitTotalOperateCostDollarSum', name: '合计',},
            {id: 'unitTotalOperateCostDollarPass', name: '达标',},
            {id: 'unitTotalOperateCostDollarFailed', name: '未达标',},

          ]
        }
      ],
      poolTypeAnalysisColumns: [
        {
          id: 'poolType', name: '油气藏类型', colSpan: 8, type: 'meta', source: 'oil-pool-type-new', isHide: () => {
            console.log('aaa', this.batchInfo.productType)
            return this.batchInfo.productType == 'gas'
          }
        },
        {
          id: 'poolType', name: '油气藏类型', colSpan: 8, type: 'meta', source: 'gas-pool-type', isHide: () => {
            return this.batchInfo.productType == 'oil'
          }
        },
        {
          id: 'totalInvest', name: '建设投资', unit: '亿元', readonly: true,
          children: [
            {id: 'totalInvestSum', name: '合计',},
            {id: 'totalInvestPass', name: '达标',},
            {id: 'totalInvestFailed', name: '未达标',},
          ]
        },
        {
          id: 'infWellCount', name: '基建井数', unit: '口', readonly: true,
          children: [
            {id: 'infWellCountSum', name: '合计',},
            {id: 'infWellCountPass', name: '达标',},
            {id: 'infWellCountFailed', name: '未达标',},
          ]
        },
        {
          id: 'newCapacity', name: '新建产能', unit: '万吨', readonly: true,
          children: [
            {id: 'newCapacitySum', name: '合计',},
            {id: 'newCapacityPass', name: '达标',},
            {id: 'newCapacityFailed', name: '未达标',},
          ]
        },
        {
          id: 'netProfit', name: '净利润', unit: '亿元', readonly: true,
          children: [
            {id: 'netProfitSum', name: '合计',},
            {id: 'netProfitPass', name: '达标',},
            {id: 'netProfitFailed', name: '未达标',},
          ]
        },
        {
          id: 'mTProductivityInvest', name: '百万吨产能投资', unit: '亿元', readonly: true,
          children: [
            {id: 'mTProductivityInvestSum', name: '合计',},
            {id: 'mTProductivityInvestPass', name: '达标',},
            {id: 'mTProductivityInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellInvest', name: '单井投资', unit: '万元', readonly: true,
          children: [
            {id: 'wellInvestSum', name: '合计',},
            {id: 'wellInvestPass', name: '达标',},
            {id: 'wellInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellEor', name: '单井EUR', unit: '吨', readonly: true,
          children: [
            {id: 'wellEorSum', name: '合计',},
            {id: 'wellEorPass', name: '达标',},
            {id: 'wellEorFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellEor', name: '单位操作成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitOperateCostDollarSum', name: '合计',},
            {id: 'unitOperateCostDollarPass', name: '达标',},
            {id: 'unitOperateCostDollarFailed', name: '未达标',},

          ]
        },
        {
          id: 'unitTotalOperateCostDollar', name: '单位完全成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitTotalOperateCostDollarSum', name: '合计',},
            {id: 'unitTotalOperateCostDollarPass', name: '达标',},
            {id: 'unitTotalOperateCostDollarFailed', name: '未达标',},

          ]
        }
      ],
      areaMarkAnalysisColumns: [
        {
          id: 'areaMark', name: '新老区', colSpan: 8, type: 'meta', source: 'area-mark'
        },

        {
          id: 'totalInvest', name: '建设投资', unit: '亿元', readonly: true,
          children: [
            {id: 'totalInvestSum', name: '合计',},
            {id: 'totalInvestPass', name: '达标',},
            {id: 'totalInvestFailed', name: '未达标',},
          ]
        },
        {
          id: 'infWellCount', name: '基建井数', unit: '口', readonly: true,
          children: [
            {id: 'infWellCountSum', name: '合计',},
            {id: 'infWellCountPass', name: '达标',},
            {id: 'infWellCountFailed', name: '未达标',},
          ]
        },
        {
          id: 'newCapacity', name: '新建产能', unit: '万吨', readonly: true,
          children: [
            {id: 'newCapacitySum', name: '合计',},
            {id: 'newCapacityPass', name: '达标',},
            {id: 'newCapacityFailed', name: '未达标',},
          ]
        },
        {
          id: 'netProfit', name: '净利润', unit: '亿元', readonly: true,
          children: [
            {id: 'netProfitSum', name: '合计',},
            {id: 'netProfitPass', name: '达标',},
            {id: 'netProfitFailed', name: '未达标',},
          ]
        },
        {
          id: 'mTProductivityInvest', name: '百万吨产能投资', unit: '亿元', readonly: true,
          children: [
            {id: 'mTProductivityInvestSum', name: '合计',},
            {id: 'mTProductivityInvestPass', name: '达标',},
            {id: 'mTProductivityInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellInvest', name: '单井投资', unit: '万元', readonly: true,
          children: [
            {id: 'wellInvestSum', name: '合计',},
            {id: 'wellInvestPass', name: '达标',},
            {id: 'wellInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellEor', name: '单井EUR', unit: '吨', readonly: true,
          children: [
            {id: 'wellEorSum', name: '合计',},
            {id: 'wellEorPass', name: '达标',},
            {id: 'wellEorFailed', name: '未达标',},
          ]
        },
        {
          id: 'unitOperateCostDollar', name: '单位操作成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitOperateCostDollarSum', name: '合计',},
            {id: 'unitOperateCostDollarPass', name: '达标',},
            {id: 'unitOperateCostDollarFailed', name: '未达标',},

          ]
        },
        {
          id: 'unitTotalOperateCostDollar', name: '单位完全成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitTotalOperateCostDollarSum', name: '合计',},
            {id: 'unitTotalOperateCostDollarPass', name: '达标',},
            {id: 'unitTotalOperateCostDollarFailed', name: '未达标',},

          ]
        }
      ],
      capacityAnalysisColumns: [
        {
          id: 'capacityType', name: '产能类型', colSpan: 8, type: 'meta', source: 'oil-capacity-type', isHide: () => {
            console.log('aaa', this.batchInfo.productType)
            return this.batchInfo.productType == 'gas'
          }
        },
        {
          id: 'capacityType', name: '产能类型', colSpan: 8, type: 'meta', source: 'gas-capacity-type', isHide: () => {
            return this.batchInfo.productType == 'oil'
          }
        },
        {
          id: 'totalInvest', name: '建设投资', unit: '亿元', readonly: true,
          children: [
            {id: 'totalInvestSum', name: '合计',},
            {id: 'totalInvestPass', name: '达标',},
            {id: 'totalInvestFailed', name: '未达标',},
          ]
        },
        {
          id: 'infWellCount', name: '基建井数', unit: '口', readonly: true,
          children: [
            {id: 'infWellCountSum', name: '合计',},
            {id: 'infWellCountPass', name: '达标',},
            {id: 'infWellCountFailed', name: '未达标',},
          ]
        },
        {
          id: 'newCapacity', name: '新建产能', unit: '万吨', readonly: true,
          children: [
            {id: 'newCapacitySum', name: '合计',},
            {id: 'newCapacityPass', name: '达标',},
            {id: 'newCapacityFailed', name: '未达标',},
          ]
        },
        {
          id: 'netProfit', name: '净利润', unit: '亿元', readonly: true,
          children: [
            {id: 'netProfitSum', name: '合计',},
            {id: 'netProfitPass', name: '达标',},
            {id: 'netProfitFailed', name: '未达标',},
          ]
        },
        {
          id: 'mTProductivityInvest', name: '百万吨产能投资', unit: '亿元', readonly: true,
          children: [
            {id: 'mTProductivityInvestSum', name: '合计',},
            {id: 'mTProductivityInvestPass', name: '达标',},
            {id: 'mTProductivityInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellInvest', name: '单井投资', unit: '万元', readonly: true,
          children: [
            {id: 'wellInvestSum', name: '合计',},
            {id: 'wellInvestPass', name: '达标',},
            {id: 'wellInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellEor', name: '单井EUR', unit: '吨', readonly: true,
          children: [
            {id: 'wellEorSum', name: '合计',},
            {id: 'wellEorPass', name: '达标',},
            {id: 'wellEorFailed', name: '未达标',},
          ]
        },
        {
          id: 'unitOperateCostDollar', name: '单位操作成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitOperateCostDollarSum', name: '合计',},
            {id: 'unitOperateCostDollarPass', name: '达标',},
            {id: 'unitOperateCostDollarFailed', name: '未达标',},

          ]
        },
        {
          id: 'unitTotalOperateCostDollar', name: '单位完全成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitTotalOperateCostDollarSum', name: '合计',},
            {id: 'unitTotalOperateCostDollarPass', name: '达标',},
            {id: 'unitTotalOperateCostDollarFailed', name: '未达标',},

          ]
        }
      ],
      regionAnalysisColumns: [
        {
          id: 'region', name: '大区', colSpan: 8, type: 'meta', source: 'oil-region', isHide: () => {
            return this.batchInfo.productType == 'gas'
          }
        },
        {
          id: 'region', name: '大区', colSpan: 8, type: 'meta', source: 'gas-region', isHide: () => {
            return this.batchInfo.productType == 'oil'
          }
        },
        {
          id: 'totalInvest', name: '建设投资', unit: '亿元', readonly: true,
          children: [
            {id: 'totalInvestSum', name: '合计',},
            {id: 'totalInvestPass', name: '达标',},
            {id: 'totalInvestFailed', name: '未达标',},
          ]
        },
        {
          id: 'infWellCount', name: '基建井数', unit: '口', readonly: true,
          children: [
            {id: 'infWellCountSum', name: '合计',},
            {id: 'infWellCountPass', name: '达标',},
            {id: 'infWellCountFailed', name: '未达标',},
          ]
        },
        {
          id: 'newCapacity', name: '新建产能', unit: '万吨', readonly: true,
          children: [
            {id: 'newCapacitySum', name: '合计',},
            {id: 'newCapacityPass', name: '达标',},
            {id: 'newCapacityFailed', name: '未达标',},
          ]
        },
        {
          id: 'netProfit', name: '净利润', unit: '亿元', readonly: true,
          children: [
            {id: 'netProfitSum', name: '合计',},
            {id: 'netProfitPass', name: '达标',},
            {id: 'netProfitFailed', name: '未达标',},
          ]
        },
        {
          id: 'mTProductivityInvest', name: '百万吨产能投资', unit: '亿元', readonly: true,
          children: [
            {id: 'mTProductivityInvestSum', name: '合计',},
            {id: 'mTProductivityInvestPass', name: '达标',},
            {id: 'mTProductivityInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellInvest', name: '单井投资', unit: '万元', readonly: true,
          children: [
            {id: 'wellInvestSum', name: '合计',},
            {id: 'wellInvestPass', name: '达标',},
            {id: 'wellInvestFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellEor', name: '单井EUR', unit: '吨', readonly: true,
          children: [
            {id: 'wellEorSum', name: '合计',},
            {id: 'wellEorPass', name: '达标',},
            {id: 'wellEorFailed', name: '未达标',},

          ]
        },
        {
          id: 'wellEor', name: '单位操作成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitOperateCostDollarSum', name: '合计',},
            {id: 'unitOperateCostDollarPass', name: '达标',},
            {id: 'unitOperateCostDollarFailed', name: '未达标',},

          ]
        },
        {
          id: 'unitTotalOperateCostDollar', name: '单位完全成本', unit: '美元/桶', readonly: true,
          children: [
            {id: 'unitTotalOperateCostDollarSum', name: '合计',},
            {id: 'unitTotalOperateCostDollarPass', name: '达标',},
            {id: 'unitTotalOperateCostDollarFailed', name: '未达标',},

          ]
        }
      ],
      profitLossBalancePriceColumns: [
        {id: 'poolType', name: '油藏类型', unit: '', readonly: true},
      ],

      profitLossBalancePriceAnalysisMockData: [],
      batchDataList: [],

    }
  },
  watch: {
    $route(to, from) {
    },
  },
  created() {
    this.loadMetaList('project-type-analysis', (dataList) => {
      this.projectTypeList = dataList;
    });
    this.loadPoolType();
    this.loadGasPoolType();
    this.loadCompany();
    this.loadGasRegion();
    this.loadOilRegion()
    this.loadOilCapacity()
    this.loadGasCapacity()

    this.loadBatchInfoList();
  },
  mounted() {
    // this.init();
  },
  methods: {
    toSum(index) {
      console.log(index)
      // return this.charDataList[0][index] + this.charDataList[1][index] + this.charDataList[2][index] +
      //     this.charDataList[3][index] + this.charDataList[4][index] + this.charDataList[5][index]
    },
    loadPoolType() {
      this.$get("/meta/type/oil-pool-type-new", {}, (response) => {
        this.poolTypeList = response.data;
        for (var i = 0; i < this.poolTypeList.length; i++) {
          this.poolTypeMap[this.poolTypeList[i].id] = this.poolTypeList[i].name;
        }

      });
    },
    loadGasPoolType() {
      this.$get("/meta/type/gas-pool-type", {}, (response) => {
        this.poolTypeList = response.data;
        for (let i = 0; i < this.poolTypeList.length; i++) {
          this.poolTypeMap[this.poolTypeList[i].id] = this.poolTypeList[i].name;
        }
      });
    },
    loadOilRegion() {
      this.$get("/meta/type/oil-region", {}, (response) => {
        for (let i = 0; i < response.data.length; i++) {
          this.regionMap[response.data[i].id] = response.data[i].name;
        }
      });
    },
    loadGasCapacity() {
      this.$get("/meta/type/gas-capacity-type", {}, (response) => {
        for (let i = 0; i < response.data.length; i++) {
          this.capacityMap[response.data[i].id] = response.data[i].name;
        }
      });
    },
    loadOilCapacity() {
      this.$get("/meta/type/oil-capacity-type", {}, (response) => {
        for (let i = 0; i < response.data.length; i++) {
          this.capacityMap[response.data[i].id] = response.data[i].name;
        }
      });
    },
    loadGasRegion() {
      this.$get("/meta/type/gas-region", {}, (response) => {
        for (let i = 0; i < response.data.length; i++) {
          this.regionMap[response.data[i].id] = response.data[i].name;
        }
      });
    },
    //组织机构
    loadCompany: async function () {
      let officeResponse = await this.$getHttpPromise("/company/tree_by_code", {code:"DQYT"});
      let officeList = officeResponse.data[0].children.filter((item)=>{return item.type!='research'  && item.type!=null});
      for (let item of officeList) {
        this.officeMap[item.id] = item.shortName;
      }
    },
    //加载评价批次数据
    loadBatchInfoList() {
      this.$get('/batch_info/data', {state: 'complete', quality: 'out_put', year: this.queryData.year}, (response) => {
        if (!response.data || response.data.length <= 0) {
          return;
        }
        this.queryData.batchId = response.data[0].id;
        this.batchDataList = response.data;
        this.handleChangeBatch(this.queryData.batchId)

      }, (response) => {
      });
    },
    getArray(list, key) {
      let arr = [];
      list.forEach(item => {
        arr.push(item[key]);
      });
      return arr;
    },
    updateBySelectOfficeTypeChart(filter) {
      let dataList = this.$refs['office-analysis'].getDataList();
      this.loadOffice(dataList, filter)
    },
    updateBySelectPoolTypeChart(filter) {

      let dataList = this.$refs['pool-type-analysis'].getDataList();
      this.loadPool(dataList, filter)
    },
    updateBySelectRegionChart(filter) {

      let dataList = this.$refs['region-analysis'].getDataList();
      this.loadRegion(dataList, filter)
    },

    updateBySelectAreaChart(filter) {

      let dataList = this.$refs['area-mark-analysis'].getDataList();
      this.loadArea(dataList, filter)
    },
    updateBySelectCapacityChart(filter) {

      let dataList = this.$refs['capacity-type-analysis'].getDataList();
      this.loadCapacity(dataList, filter)
    },
    loadRegion(dataList, filter) {
      this.loadChart(dataList, this.regionAnalysisOption, 'region', this.regionSelectKey)

    },
    loadOffice(dataList, filter) {
      this.loadChart(dataList, this.officeAnalysisOption, 'office', this.officeSelectKey)

    },
    loadArea(dataList, filter) {
      this.loadChart(dataList, this.areaAnalysisOption, 'area', this.areaSelectKey)

    },
    loadCapacity(dataList, filter) {
      this.loadChart(dataList, this.capacityAnalysisOption, 'capacity', this.capacitySelectKey)

    },
    loadPool(dataList, filter) {

      this.loadChart(dataList, this.poolAnalysisOption, 'pool', this.poolTypeSelectKey)

    },

    // BalancePriceChartOption
    loadChart(dataList, targetOption, type, filterType) {
      targetOption.xAxis.data = []
      targetOption.series[0].data = []
      targetOption.series[1].data = []
      targetOption.series[2].data = []
      if (!dataList || dataList.length == 0) {
        return
      }

      if (!filterType) {
        filterType = 'totalInvest'
      }
      for (let item of dataList) {
        let category = ''
        if (type == 'office') {
          category = this.officeMap[item.buildOffice]
        } else if (type == 'pool') {
          category = this.poolTypeMap[item.poolType]
        } else if (type == 'region') {
          category = this.regionMap[item.region]
        } else if (type == 'area') {
          category = item.areaMark == 'new' ? '新区' : '老区'
        } else if (type=='capacity') {
          console.log(JSON.stringify(this.capacityMap))
          category = this.capacityMap[item.capacityType]
        }
        targetOption.xAxis.data.push(category);

        targetOption.series[0].data.push(item[filterType + 'Pass'])
        targetOption.series[1].data.push(item[filterType + 'Failed'])
        targetOption.series[2].data.push(item[filterType + 'Sum'])
      }
      if (dataList.length <= 5) {
        this.setBatWidth(targetOption.series, '20%')
      } else if (dataList.length <= 4) {
        this.setBatWidth(targetOption.series, '20%')
      } else if (dataList.length <= 2) {
        this.setBatWidth(targetOption.series, '15%')
      }
      if (dataList.length >= 10) {
        this.setBatWidth(targetOption.series, '40%')
      }
      return targetOption

    },
    setBatWidth(seriesList, width) {
      for (let series of seriesList) {
        series.barWidth = width
      }
    },
    //处理年份变更,重新加载数据
    handleChangeYear(year) {

      this.queryData.year = year
      /*let queryTable = this.$refs[this.activeTab];
      queryTable.updateQueryCondition('year', year);
      queryTable.loadDataList();*/
      this.loadBatchInfoList();
    },
    //处理年份变更,重新加载数据
    handleChangeBatch(batchId) {
      for (let item of this.batchDataList) {
        if (item.id == batchId) {
          this.batchInfo = item
          break;
        }
      }
      let queryTable = this.$refs[this.activeTab];
      queryTable.updateQueryCondition('batchId', batchId);
      queryTable.loadDataList();

    },

  },
}
</script>